package com.cmo.rzl.triage;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.beetl.sql.core.kit.StringKit;

import com.cmo.rzl.core.base.BaseController;
import com.cmo.rzl.core.jfinal.ext.autoroute.ControllerBind;
import com.cmo.rzl.core.toolbox.Record;
import com.cmo.rzl.core.toolbox.kit.ShardKit;
import com.cmo.rzl.shine.service.DoctorService;
import com.cmo.rzl.shine.service.Pager2terminalService;
import com.cmo.rzl.shine.service.impl.DoctorServiceImpl;
import com.cmo.rzl.shine.service.impl.Pager2terminalServiceImpl;

@ControllerBind(controllerKey="/clientdoctor")
public class ClientDoctorController extends BaseController {

	ShardKit shard=new ShardKit();
	DoctorService service=new DoctorServiceImpl();
	Pager2terminalService ptservice=new Pager2terminalServiceImpl();
	//医生信息列表
	public void list_doctor(){
		Map<String, Object> map=new HashMap<String, Object>();
		List<Record> list= service.list_doctor();
		if(list.isEmpty()){
			map.put("return_code", "fail");
			map.put("return_msg", "查询失败");
			renderJson(map);
			return;
		}else{
			map.put("return_code", "success");
			map.put("return_msg", "查询医生成功");
			map.put("count", list.size());
			map.put("list", list);
			renderJson(map);
		}
	}
	
	public void doctor_room_door(){
		Map<String, Object> map=new HashMap<String, Object>();
		//获取屏的ip
		String ip=shard.getIpAddr(getRequest());
		if(StringKit.isBlank(ip)){
			map.put("return_code", "fail");
			map.put("return_msg", "获取屏ip失败");
			renderJson(map);
			return;
		}
		//根据获取屏的ip查询绑定关系
		Record r= ptservice.findByIP(ip);
		if(null==r){
			map.put("return_code", "fail");
			map.put("return_msg", "该屏还跟叫号器绑定关系");
			renderJson(map);
			return;
		}
		//String pager_ip=r.getStr("ip");
		Record record= service.queryByip(ip);
		if(null==record){
			map.put("return_code", "fail");
			map.put("return_msg", "还未有医生登陆诊室");
			renderJson(map);
			return;
		}else{
			map.put("return_code", "success");
			map.put("return_msg", "信息查询成功");
			map.put("doctorinfo", record);
			renderJson(map);
		}
	}
}
